package com.itclass.auth.authentication.adapter.support;

import com.itclass.auth.authentication.adapter.AbstractAuthenticationAdapter;
import com.itclass.auth.authentication.token.supprt.GitHubLoginAuthenticationToken;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class GitHubAuthAuthenticationAdapter extends AbstractAuthenticationAdapter<HttpServletRequest, GitHubLoginAuthenticationToken> {


    public GitHubAuthAuthenticationAdapter() {
        super("github");
    }

    @Override
    public boolean supports(String loginTypeName) {
        return this.getLoginType().equals(loginTypeName);
    }

    @Override
    public GitHubLoginAuthenticationToken handle(HttpServletRequest request) {
        String code = request.getParameter("code");
        GitHubLoginAuthenticationToken gitHubLoginAuthenticationToken = new GitHubLoginAuthenticationToken(false,code);
        return gitHubLoginAuthenticationToken;
    }
}
